Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for large projects #4419

Merged
merged 50 commits into from
Aug 24, 2023

Conversation

keyboardDrummer
Copy link
Member

@keyboardDrummer keyboardDrummer commented Aug 15, 2023

Changes

  • Sample sending notifications to the IDE, so at most one is sent every 100ms. Relatedly, IdeState is computed lazily, so it is not computed for notifications that are not sent to the IDE.
  • Cancel ongoing compilation work and notification publishing immediately when UpdateDocument is entered
  • Start a new compilation slightly earlier, before computing the most recently changed ranges
  • Fix migration of recently changed ranges, so it properly accounts for Uri differences.
  • Optimize search for source files by starting from the common parent of all include globs instead of the disk root.
  • Make sure only one (correct) version of WriterFromOutputHelper is used in all test projects, to help in debugging non-deterministic failures
  • Small changes to IncrementalVerificationDiagnosticsBetweenMethods to help in debugging non-deterministic failures

Testing

  • Add a test QuickEditsInLargeFile with a 1000 line and method file, that instantly makes a 100 small edits to that file, and asserts that the language server can process these changes in at most three times as much time as it takes to open the file.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

keyboardDrummer added a commit that referenced this pull request Aug 18, 2023
### Changes

1. Rename `LegacySymbolTable`, which is part of the non-LSP Dafny
server, to `SuperLegacySymbolTable`
1. Rename `SignatureAndCompletionTable` to
`LegacySignatureAndCompletionTable`
1. Let `SignatureAndCompletionTable` differentiate between positions in
different files, so it doesn't get confused between symbols in different
files when they have similar positions or ranges.
1. Only migrate state in `SignatureAndCompletionTable` that relates to
the changed file

### Testing
- There could be a test added for 3 but I didn't add it.
- Merging this PR into this other PR
(#4419), reduces the time of the
test `ManyFastEditsUsingLargeFilesAndIncludes` from 47 seconds to 8
seconds

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Copy link
Member

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall according to my understanding it looks good. A few questions there and there.

Source/DafnyCore/Generic/Lazy.cs Outdated Show resolved Hide resolved
Source/DafnyCore/Generic/Util.cs Outdated Show resolved Hide resolved
lowest = Math.Min(lowest, division);

// Commented code left in intentionally
await output.WriteLineAsync("openMilliseconds: " + openMilliseconds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use logging here instead of all these output.WriteLineAsync?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no logger available inside the test files.

await output.WriteLineAsync("changeMilliseconds: " + changeMilliseconds);
await output.WriteLineAsync("division: " + division);
try {
Assert.True(division < 10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please justify why this threshold? Also please consider introducing a constant at the top of the class

Source/DafnyPipeline.Test/Trivia.cs Show resolved Hide resolved
Source/DafnyTestGeneration.Test/BasicTypes.cs Show resolved Hide resolved
Source/DafnyTestGeneration.Test/Various.cs Show resolved Hide resolved
Copy link
Contributor

@jtristan jtristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that the imports flagged as potentially not being used are in fact used or remove them? Should we add a test as suggested by Mikael?

var newRange = changeProcessor.MigrateRange(location.Range);
if (location.Uri != documentChange.TextDocument.Uri) {
return location;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one?

@keyboardDrummer keyboardDrummer merged commit c547336 into dafny-lang:master Aug 24, 2023
18 checks passed
@keyboardDrummer keyboardDrummer deleted the largeFilesTest branch August 24, 2023 14:29
keyboardDrummer added a commit to keyboardDrummer/dafny that referenced this pull request Sep 15, 2023
### Changes

1. Rename `LegacySymbolTable`, which is part of the non-LSP Dafny
server, to `SuperLegacySymbolTable`
1. Rename `SignatureAndCompletionTable` to
`LegacySignatureAndCompletionTable`
1. Let `SignatureAndCompletionTable` differentiate between positions in
different files, so it doesn't get confused between symbols in different
files when they have similar positions or ranges.
1. Only migrate state in `SignatureAndCompletionTable` that relates to
the changed file

### Testing
- There could be a test added for 3 but I didn't add it.
- Merging this PR into this other PR
(dafny-lang#4419), reduces the time of the
test `ManyFastEditsUsingLargeFilesAndIncludes` from 47 seconds to 8
seconds

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
keyboardDrummer added a commit to keyboardDrummer/dafny that referenced this pull request Sep 15, 2023
### Changes
- Sample sending notifications to the IDE, so at most one is sent every
100ms. Relatedly, `IdeState` is computed lazily, so it not computed for
notifications that are not sent to the IDE.
- Cancel ongoing compilation work and notification publishing
immediately when UpdateDocument is entered
- Start a new compilation slightly earlier, before computing the most
recently changed ranges
- Fix migration of recently changed ranges, so it properly accounts for
Uri differences.
- Make sure only one (correct) version of `WriterFromOutputHelper` is
used in all test projects, to help in debugging non-deterministic
failures
- Small changes to `IncrementalVerificationDiagnosticsBetweenMethods` to
help in debugging non-deterministic failures

### Testing
- Add a test `QuickEditsInLargeFile` with a 1000 line and method file,
that instantly makes a 100 small edits to that file, and asserts that
the language server can process these changes in at most three times as
much time as it takes to open the file.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
keyboardDrummer added a commit that referenced this pull request Sep 19, 2023
### Changes

1. Rename `LegacySymbolTable`, which is part of the non-LSP Dafny
server, to `SuperLegacySymbolTable`
1. Rename `SignatureAndCompletionTable` to
`LegacySignatureAndCompletionTable`
1. Let `SignatureAndCompletionTable` differentiate between positions in
different files, so it doesn't get confused between symbols in different
files when they have similar positions or ranges.
1. Only migrate state in `SignatureAndCompletionTable` that relates to
the changed file

### Testing
- There could be a test added for 3 but I didn't add it.
- Merging this PR into this other PR
(#4419), reduces the time of the
test `ManyFastEditsUsingLargeFilesAndIncludes` from 47 seconds to 8
seconds

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
keyboardDrummer added a commit that referenced this pull request Sep 19, 2023
### Changes
- Sample sending notifications to the IDE, so at most one is sent every
100ms. Relatedly, `IdeState` is computed lazily, so it not computed for
notifications that are not sent to the IDE.
- Cancel ongoing compilation work and notification publishing
immediately when UpdateDocument is entered
- Start a new compilation slightly earlier, before computing the most
recently changed ranges
- Fix migration of recently changed ranges, so it properly accounts for
Uri differences.
- Make sure only one (correct) version of `WriterFromOutputHelper` is
used in all test projects, to help in debugging non-deterministic
failures
- Small changes to `IncrementalVerificationDiagnosticsBetweenMethods` to
help in debugging non-deterministic failures

### Testing
- Add a test `QuickEditsInLargeFile` with a 1000 line and method file,
that instantly makes a 100 small edits to that file, and asserts that
the language server can process these changes in at most three times as
much time as it takes to open the file.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker Must be resolved before the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants